﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMC;
using System.Net.Sockets;
using System.IO;
using System.Reflection;
using DatabaseModule;

namespace Server
{
    public class UserHandler
    {
        private Socket clientSocket;
        private UserManagement userman;

        public UserHandler(Socket clientSock)
        {
            clientSocket = clientSock;
            string dbConfigFile = @"./db_settings.xml";
            databaseConfiguration config = new databaseConfiguration(dbConfigFile);
            
            userman = new UserManagement(config);

        }

        public bool handleUser(string[] message)
        {
            bool ret = false;
            System.Diagnostics.Debug.WriteLine(message[2]);
            if (message[2] == "LOGIN")
            {
                ret = userman.authenticateUser(message[3], message[4]);
            }
            else if (message[2] == "GET")
            {
                ret = false;
            }
            else if (message[2] == "CREATE")
            {
                
                ret = userman.adduser(message[3], message[4], message[5], message[6],message[7],message[8]);
            }
            else if (message[2] == "DELETE")
            {
                ret = userman.delUser(message[3]);
              
            }
            else
            {
                ret = false;
            }

            return ret;
        }

        
    }
}
